package com.hctrl.mybatis.result;

import java.io.Serializable;

/**
 * @author      yzr
 * @date        2021/09/09
 * @description 相响应基本参数
 **/
public class BaseResult implements Serializable {

    private static final long serialVersionUID = 950756583634540858L;

    private boolean success;
    private String message;
    private int code;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static BaseResult buildSuccess(){
        BaseResult result = new BaseResult();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        return result;
    }

    public static BaseResult buildSuccess(String message){
        BaseResult result = new BaseResult();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(message);
        return result;
    }

    public static BaseResult buildFailure(int code, String message){
        BaseResult result = new BaseResult();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static BaseResult buildFailure(ResultCode resultCode){
        return buildFailure(resultCode.getCode(), resultCode.getMessage());
    }
}
